package projectdemo01.operation;

import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
import projectdemo01.book.Book;
import projectdemo01.book.BookList;

import java.util.Scanner;
import java.util.jar.JarOutputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 09 - 23
 * Time:19:48
 */

/***
 * 2.查找图书：根据输入的额图书名字，遍历顺序表BookList进行查找
 */
public class FindOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("查找书籍");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要查找的图书名字：");
        String bookname = scanner.nextLine();
        //根据输入的图书名字，遍历顺序表，进行查找
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(bookname)){
                System.out.println("查找到了此书籍！");
                System.out.println(book);
                return;
            }
        }
        System.out.println("没有查找到此书籍");
    }
}
